const DEVELOPMENT = 'development'
const PRODUCT = 'production'
const TEST = 'test'

class ProxyConfig {
  constructor(env) {
    this.env = env
  }
  // get token() {
  //   return 'eyJraWQiOiJhaS0xNDVjZTc1ZWFjNmM0NjI3YTBlZWMwNjlhZTIyNWE4Zjpzc28iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ1cy1lZjE1ZDg1NmJlYzU0YzcyYTkxYWUzZjZlNmQyNjY1YSIsIm5iZiI6MTY0NDU0NzA5OCwidXNlcl9pZCI6InVzLWVmMTVkODU2YmVjNTRjNzJhOTFhZTNmNmU2ZDI2NjVhIiwiYXpwIjoiYWktMTQ1Y2U3NWVhYzZjNDYyN2EwZWVjMDY5YWUyMjVhOGYiLCJ0bnRfaWQiOiJ0bi1mYzBiNmE1MTQzYjk0OTU4YjY2ZDdiOTE3YmZkYThiYSIsImlzcyI6Imh0dHBzOlwvXC9jb29scGFkLWlkcC5jaWcudGVuY2VudGNzLmNvbSIsIm5hbWUiOiLmnY7mmajovokiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJsaWNoZW5odWkiLCJleHAiOjE2NDQ1NDg4OTgsImlhdCI6MTY0NDU0NzA5OCwianRpIjoiNTQ0ZTQwNzktMzUxNi00MmU5LWFiZDEtMTM1Njk4NGI2MTFjIn0.ATqvuRkJSv9gxKY14vOyjpVuwTCPIRnaddt_O2k2ShQgN88OXOr-P78RPT65OY39Euoov2B_kf_AMs6n7MQUepN7LlhqBUywKKJuSy2vtbuyDRU1lIY_CX_6FbfZPNI-GftL0lLx9HnzZgvUaorD1vBHnSEnAx-U3a1nBxj20zTAgmVNV2yXDkjATcFYFIqFtJHwnd_nQ9WDVQybe8Z2IV9sBjnOllsVTB39AmFhgKM7sI_aIC5XAaNiktbjjJdNriqMqR5Y5Ks4TThhSwrCRr1b9RzdGMmo_vGNO5nnYr8vIc0I3JAnHorrNqZrVnxtczuXXXdC85AKq8VnlwnXtA'
  // }
  // get subject() {
  //   return 'us-461936c4d25148739c2a64c157663e7b'
  // }
  get [DEVELOPMENT]() {
    return {
      tiger: {
        api: 'http://tiger-test.api.coolpad.com'
      },
      album: {
        api: 'http://tiger-test.api.coolpad.com/duck',
        // api: 'http://10.10.32.38:8080',
        environment: DEVELOPMENT,
        pathRewrite: {
          '^/admin': '/api/v1'
        }
      },
      base: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      application: {
        // api: '10.10.82.36:8100'
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      taotao: {
        // api: 'http://10.10.82.37:8100'
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      xinwei: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      xinwei_duck: {
        api: 'http://tiger-test.api.coolpad.com/duck'
      },
      test: {
        api: 'http://tiger-test.api.coolpad.com/duck',
        environment: DEVELOPMENT,
        pathRewrite: {
          '^/admin': '/api/v1'
        }
      },
      liuhui: {
        // api: 'http://10.11.222.166:8082'
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      xiaoqi: {
        // api: 'http://10.10.82.61:8088'
        api: 'http://tiger-test.api.coolpad.com/duck'
      },
      junhao: {
        // api: 'http://10.10.82.70:8100'
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      htt: {
        // api: 'http://10.10.32.36:8100'
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      htt_pre: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      linjun: {
        api: 'http://10.10.82.34:8100'
      },
      ch: {
        // api: 'http://10.10.32.16:8100'
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      jw: {
        // api: 'http://10.10.32.25:8082'
        api: 'http://tiger-test.api.coolpad.com/applet'
      },
      lh: {
        // api: 'http://10.11.222.166:8082'
        api: 'http://tiger-test.api.coolpad.com/applet'
      },
      mario: {
        api: 'http://tiger-test.api.coolpad.com/mario'
      }
    }
  }
  get [TEST]() {
    return {
      tiger: {
        api: 'http://tiger-test.api.coolpad.com'
      },
      base: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      xinwei: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      xinwei_duck: {
        api: 'http://tiger-test.api.coolpad.com/duck'
      },
      liuhui: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      taotao: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      test: {
        api: 'http://tiger-test.api.coolpad.com/duck',
        environment: TEST,
        pathRewrite: {
          '^/admin': '/api/v1'
        }
      },
      album: {
        api: 'http://tiger-test.api.coolpad.com/duck',
        environment: TEST,
        pathRewrite: {
          '^/admin': '/api/v1'
        }
      },
      xiaoqi: {
        api: 'http://tiger-test.api.coolpad.com/duck'
      },
      htt: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      htt_pre: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      junhao: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      ch: {
        api: 'http://tiger-test.api.coolpad.com/appstore'
      },
      jw: {
        api: 'http://tiger-test.api.coolpad.com/applet'
      },
      lh: {
        api: 'http://tiger-test.api.coolpad.com/applet'
      },
      mario: {
        api: 'http://tiger-test.api.coolpad.com/mario'
      }
    }
  }
  get [PRODUCT]() {
    return {
      tiger: {
        api: 'https://tiger.api.coolpad.com'
      },
      base: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      xinwei: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      xinwei_duck: {
        api: 'https://tiger.api.coolpad.com/duck'
      },
      liuhui: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      taotao: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      test: {
        api: 'https://tiger.api.coolpad.com/duck',
        environment: PRODUCT,
        pathRewrite: {
          '^/admin': '/api/v1'
        }
      },
      album: {
        api: 'https://tiger.api.coolpad.com/duck',
        environment: PRODUCT,
        pathRewrite: {
          '^/admin': '/api/v1'
        }
      },
      xiaoqi: {
        api: 'https://tiger.api.coolpad.com/duck'
      },
      htt: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      htt_pre: {
        // api: 'https://appstore-pre.api.coolpad.com/appstore'
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      junhao: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      ch: {
        api: 'https://tiger.api.coolpad.com/appstore'
      },
      jw: {
        api: 'https://tiger.api.coolpad.com/applet'
      },
      lh: {
        api: 'https://tiger.api.coolpad.com/applet'
      },
      mario: {
        api: 'https://tiger.api.coolpad.com/mario'
      }
    }
  }

  get baseConfig() {
    switch (this.env) {
      case DEVELOPMENT:
        return this[DEVELOPMENT]
      case TEST:
        return this[TEST]
      case PRODUCT:
        return this[PRODUCT]
      default:
        return {}
    }
  }
  getBaseURL(baseApi) {
    return (this.baseConfig[baseApi] && this.baseConfig[baseApi]['api']) || ''
  }
  proxyUrl(baseApi, config) {
    if (!this.baseConfig[baseApi] || !this.baseConfig[baseApi]['environment']) {
      return
    }
    const baseUrl = config.baseURL || ''
    let api = config.url.replace(baseUrl, '')
    const pathRewrite = this.baseConfig[baseApi]['pathRewrite'] || {}
    Object.entries(pathRewrite).forEach(([key, value]) => {
      api = api.replace(new RegExp(key), value)
    })
    config.url = baseUrl + api
  }
}
export default new ProxyConfig(process.env.VUE_APP_ENV)
